//
//  HYNewsViewController.m
//  HaiYue
//
//  Created by skyline on 2018/1/19.
//  Copyright © 2018年 skyline. All rights reserved.
//

#import "HYNewsViewController.h"
#import "HYFeedBackViewController.h"
CGFloat const NEWCELLHEIGHT = 60;
@interface HYNewsViewController ()<UITableViewDelegate,UITableViewDataSource>
@property (nonatomic, strong) UITableView *tableView;
@property (nonatomic, strong) NSArray *array;
@end

@implementation HYNewsViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.title = @"消息中心";
    // Do any additional setup after loading the view.
}

- (NSArray *)array
{
    if (!_array)
    {
        _array = @[@"通知消息",@"用户帮助",@"意见反馈",@"联系客服"];
    }
    return _array;
}

- (UITableView *)tableView
{
    if (!_tableView)
    {
        _tableView = [[UITableView alloc] init];
        _tableView.delegate = self;
        _tableView.dataSource = self;
        _tableView.scrollEnabled = NO;
                _tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
//        _tableView.separatorColor = CELL_LINE_COLOR;
        [self.view addSubview:_tableView];
        [_tableView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.edges.mas_offset(UIEdgeInsetsZero);
        }];
    }
    return _tableView;
}

#pragma mark UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return self.array.count;//多处的一个cell的下划线
}
- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    NSString *identifier = @"NewsCell";
    HYTableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:identifier];
    if (!cell)
    {
        cell = [[HYTableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:identifier];
    }
    cell.textLabel.text = self.array[indexPath.row];
    cell.separatorInset = UIEdgeInsetsZero;
    HYImageView *imgView= [[HYImageView alloc]initWithImage:[UIImage imageNamed:@"rightArrow_select"]];
    imgView.bounds = CGRectMake(0, 0, HYCellRightArrowWidth, HYCellRightArrowHeight);
    [cell addSubview:imgView];
    [imgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.right.equalTo(cell).with.offset(- GAP );
        make.centerY.equalTo(cell);
        make.size.mas_equalTo(imgView.bounds.size);
    }];
    
   HYView *line = [[HYView alloc] initWithColor:CELL_LINE_COLOR];
    [cell addSubview:line];
    [line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(cell);
        make.right.equalTo(cell);
        make.bottom.equalTo(cell);
        make.height.mas_equalTo(0.5);
    }];
    return cell;
}

#pragma mark UITableViewDelegate

- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return NEWCELLHEIGHT;
}

- (nullable UIView *)tableView:(UITableView *)tableView viewForFooterInSection:(NSInteger)section
{
    return [[UIView alloc] initWithFrame:CGRectZero];
}

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    id vc;
    if (indexPath.row == 0)
    {
        vc = [NSClassFromString(@"HYNotifyNewsViewController") new];
    }
    else if (indexPath.row == 1)
    {
        vc = [NSClassFromString(@"HYHelpViewController") new];
    }
    else if (indexPath.row == 2)
    {
        vc = [NSClassFromString(@"HYFeedBackViewController") new];
        [vc setValue:@"意见反馈" forKeyPath:@"title"];
        [vc setValue:API_DO_FEEDCK forKey:@"api"];
        [vc setValue:@"提交反馈" forKeyPath:@"buttonTitle"];
        [vc setValue:@"请提出您的意见与建议，管理员回复后会在消息中心通知您" forKeyPath:@"textView.placholder"];
    }
    else if (indexPath.row == 3)
    {
        return [AppDelegate openQQ];
    }
    [self.navigationController pushViewController:vc animated:YES];
}


- (void)viewWillAppear:(BOOL)animated
{
    [super viewWillAppear:animated];
    self.style = HYViewNaviBarStyleOnlyLeftBtn;
    self.tableView.hidden = NO;
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
 #pragma mark - Navigation
 
 // In a storyboard-based application, you will often want to do a little preparation before navigation
 - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
 // Get the new view controller using [segue destinationViewController].
 // Pass the selected object to the new view controller.
 }
 */

@end
